package com.baiyun.controller.admin;


import com.baiyun.Result.Result;
import com.baiyun.entity.Sale;
import com.baiyun.service.SalesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/sales")
@RequiredArgsConstructor
@Api(tags = "管理员端——销售管理")
public class SalesController {
    private final SalesService salesService;

    /**
     * 询所有销售记录
     * @return
     */
    @GetMapping()
    @ApiOperation("询所有销售记录")
    public Result<List<Sale>> selectAllSales(){
        log.info("询所有销售记录");
        return Result.success(salesService.selectAllSales());
    }

    /**
     * 添加销售记录
     * @return
     */
    @PostMapping()
    @ApiOperation("添加销售记录")
    public Result addSales(@RequestBody Sale sale){
        log.info("添加销售记录");
        salesService.addSales(sale);
        return Result.success();
    }

    /**
     * 修改销售记录
     * @return
     */
    @PutMapping()
    @ApiOperation("修改销售记录")
    public Result updateSales(@RequestBody Sale sale){
        log.info("修改销售记录");
        salesService.updateSales(sale);
        return Result.success();
    }

    /**
     * 删除销售记录
     * @return
     */
    @DeleteMapping("/{sid}")
    @ApiOperation("删除销售记录")
    public Result deleteSales(@ApiParam("订单sid") @PathVariable("sid") Integer sid){
        log.info("删除销售记录");
        salesService.deleteSales(sid);
        return Result.success();
    }

    /**
     * 按ID查询销售记录
     * @return
     */
    @GetMapping("/{sid}")
    @ApiOperation("按ID查询销售记录")
    public Result getSaleById(@ApiParam("订单sid") @PathVariable("sid") Integer sid){
        log.info("按ID查询销售记录");
        return Result.success(salesService.getSaleById(sid));
    }
}
